package edu.ptit.jad.model;

import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Content {

	private int id;
	private String text;

	private String[] terms;
	private int[] termFrequencies;
	private Map<String, Integer> tfMap;

	public Content() {
	}

	public Content(int id, String text) {

		this.id = id;
		this.text = text;

	}

	public Map<String, Integer> buildTermFrequencyMap(String text) {

		Map<String, Integer> termFrequencyMap = new HashMap<String, Integer>();

		StringTokenizer tknr = new StringTokenizer(text, " ");
		String term = "";

		while (tknr.hasMoreTokens()) {

			// allTermsSet.add(tknr.nextToken());
			term = tknr.nextToken();
			Integer frequency = termFrequencyMap.get(term);
			if (frequency == null) {
				termFrequencyMap.put(term, 1);
			} else {
				termFrequencyMap.put(term, frequency + 1);
			}
		}

		return termFrequencyMap;
	}

	public static void main(String[] args) {

		Content content = new Content();
		Map<String, Integer> termFrequencyMap = content
				.buildTermFrequencyMap("this is the man is the day of the sun");
		for (Map.Entry<String, Integer> e : termFrequencyMap.entrySet())
			System.out.println(e.getKey() + ": " + e.getValue());

	}

}
